package com.cloudsigns.factorymanager2.produce.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.produce.bean.request.ScheduleDay;

import java.util.ArrayList;
import java.util.List;

public class ProduceModifyPlanInformationAdapter extends BaseAdapter{
    private Context context;
    private List<ScheduleDay> datas = new ArrayList<ScheduleDay>();
    private LayoutInflater inflater;

    public ProduceModifyPlanInformationAdapter(Context context) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    public void setData(List<ScheduleDay> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public ScheduleDay getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_produce_modify_plan_information, null);
            holder = new ViewHolder(convertView, position);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
            holder.tv_num.setTag(position);
        }

        ScheduleDay workPartScheduleBean = datas.get(position);
        holder.tv_date.setText(workPartScheduleBean.getStrTime());
        holder.tv_num.setText(String.valueOf(workPartScheduleBean.getAmount()));

        return convertView;
    }

    private class ViewHolder {
        private TextView tv_date;
        private TextView tv_num;

        public ViewHolder(View view, int position) {
            tv_date = view.findViewById(R.id.tv_date);
            tv_num = view.findViewById(R.id.tv_num);
        }
    }
}
